import 'package:finance_app/src/entities/ocr_attachment_entity.dart';
import 'package:finance_app/src/entities/business_contact_entity.dart';
import 'package:finance_app/src/entities/expense_detail_entity.dart';
import 'package:finance_app/src/entities/setting_data_entity.dart';

ocrAttachmentEntityFromJson(OcrAttachmentEntity data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['is_image'] != null) {
		data.isImage = json['is_image'] is String
				? int.tryParse(json['is_image'])
				: json['is_image'].toInt();
	}
	if (json['thumbnail'] != null) {
		data.thumbnail = json['thumbnail'].toString();
	}
	if (json['url'] != null) {
		data.url = json['url'].toString();
	}
	if (json['ocr_data'] != null) {
		data.ocrData = OcrAttachmentOcrData().fromJson(json['ocr_data']);
	}
	return data;
}

Map<String, dynamic> ocrAttachmentEntityToJson(OcrAttachmentEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['is_image'] = entity.isImage;
	data['thumbnail'] = entity.thumbnail;
	data['url'] = entity.url;
	data['ocr_data'] = entity.ocrData?.toJson();
	return data;
}

ocrAttachmentOcrDataFromJson(OcrAttachmentOcrData data, Map<String, dynamic> json) {
	if (json['type'] != null) {
		data.type = json['type'].toString();
	}
	if (json['contact_id'] != null) {
		data.contactId = json['contact_id'] is String
				? int.tryParse(json['contact_id'])
				: json['contact_id'].toInt();
	}
	if (json['business_contact_name'] != null) {
		data.businessContactName = json['business_contact_name'].toString();
	}
	if (json['category'] != null) {
		data.category = json['category'].toString();
	}
	if (json['currency'] != null) {
		data.currency = json['currency'].toString();
	}
	if (json['invoice_number'] != null) {
		data.invoiceNumber = json['invoice_number'].toString();
	}
	if (json['items'] != null) {
		data.items = (json['items'] as List).map((v) => ExpenseDetailItems().fromJson(v)).toList();
	}
	if (json['order_date'] != null) {
		data.orderDate = json['order_date'].toString();
	}
	if (json['subtotal'] != null) {
		data.subtotal = json['subtotal'] is String
				? num.tryParse(json['subtotal'])
				: json['subtotal'];
	}
	if (json['tax_amount'] != null) {
		data.taxAmount = json['tax_amount'] is String
				? int.tryParse(json['tax_amount'])
				: json['tax_amount'].toInt();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? num.tryParse(json['total'])
				: json['total'];
	}
	if (json['payment_type'] != null) {
		data.paymentType = SettingDataPaymentType().fromJson(json['payment_type']);
	}
	if (json['contact'] != null) {
		data.contact = BusinessContactEntity().fromJson(json['contact']);
	}
	return data;
}

Map<String, dynamic> ocrAttachmentOcrDataToJson(OcrAttachmentOcrData entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['type'] = entity.type;
	data['contact_id'] = entity.contactId;
	data['business_contact_name'] = entity.businessContactName;
	data['category'] = entity.category;
	data['currency'] = entity.currency;
	data['invoice_number'] = entity.invoiceNumber;
	data['items'] =  entity.items?.map((v) => v.toJson())?.toList();
	data['order_date'] = entity.orderDate;
	data['subtotal'] = entity.subtotal;
	data['tax_amount'] = entity.taxAmount;
	data['total'] = entity.total;
	data['payment_type'] = entity.paymentType?.toJson();
	data['contact'] = entity.contact?.toJson();
	return data;
}